<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- Meta, title, CSS, favicons, etc. -->
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>随便打TCS系统</title>
<!-- Bootstrap -->
<link href="<%=basePath%>vendors/bootstrap/dist/css/bootstrap.min.css"
	rel="stylesheet">
<!-- Font Awesome -->
<link
	href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css"
	rel="stylesheet">
<!-- Select2 -->
<link href="<%=basePath%>vendors/select2/dist/css/select2.min.css"
	rel="stylesheet">
<!-- NProgress -->
<link href="<%=basePath%>vendors/nprogress/nprogress.css"
	rel="stylesheet">
<!-- iCheck -->
<link href="<%=basePath%>vendors/iCheck/skins/flat/green.css"
	rel="stylesheet">

<!-- bootstrap-progressbar -->
<link
	href="<%=basePath%>vendors/bootstrap-progressbar/css/bootstrap-progressbar-3.3.4.min.css"
	rel="stylesheet">
<!-- JQVMap -->
<link href="<%=basePath%>vendors/jqvmap/dist/jqvmap.min.css"
	rel="stylesheet" />
<!-- bootstrap-daterangepicker -->
<link
	href="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.css"
	rel="stylesheet">

<!-- Custom Theme Style -->
<link href="<%=basePath%>build/css/custom.min.css" rel="stylesheet">
</head>
<%@ include file="loginCheck.jsp"%>
<body class="nav-md">
	<div class="container body">
		<div class="main_container">
			<div class="col-md-3 left_col">
				<div class="left_col scroll-view">
					<div class="clearfix"></div>
					<br />
				</div>
			</div>
			<!-- page content -->
			<div class="right_col" role="main">
				<div class="">
					<div class="page-title">
						<div class="title_left">
							<h3>每日任务信息</h3>
						</div>
					</div>
					<div class="clearfix"></div>
					<div class="row">
						<div class="col-md-12 col-sm-12 col-xs-12">
							<div class="x_panel">
								<div class="x_title">
									<h2>创建一个新的每日任务信息</h2>
									<div class="clearfix"></div>
								</div>
								<div class="x_content">
									<form name="myForm" class="form-horizontal form-label-left"
										novalidate method="post" enctype="multipart/form-data"
										id="myForm">
										<p>
											您需要将以下内容填写完整后才可以创建每日任务，如有疑问请
											<code>联系客服</code>
											以帮助您完成相关配置以及信息完善
										</p>
										<span class="section">基本信息</span>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">任务类型 </label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="type" name="type" onchange="show(this)">
													<option value="1" selected>登录</option>
													<option value="2">分享</option>
													<option value="3">购物</option>
													<option value="4">看广告</option>
													<option value="5">看新闻</option>
													<option value="6">完善个人信息</option>
												</select>
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">赠送通话金额 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="presenttf"
													class="form-control col-md-7 col-xs-12" name="presenttf"
													type="text" value="" placeholder="例如：5.00">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">赠送购物金额 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="presentsg"
													class="form-control col-md-7 col-xs-12" name="presentsg"
													type="text" value="" placeholder="例如：5.00">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">目标值 <span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="target" class="form-control col-md-7 col-xs-12"
													name="target" type="text" value="" placeholder="例如：3">
											</div>
										</div>
										<div class="item form-group" id="shopmoney_box" style="display:none;">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												   for="name">跳转地址 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="url" class="form-control col-md-7 col-xs-12"
													   name="url" placeholder="例如：www.baidu.com" required="required"
													   type="text">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">优先级 <span class="required"></span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<input id="priority" class="form-control col-md-7 col-xs-12"
													name="priority" type="text" value="" placeholder="例如：1（最小）">
											</div>
										</div>
										<div class="item form-group">
											<label class="control-label col-md-3 col-sm-3 col-xs-12"
												for="name">状态 <span class="required">*</span>
											</label>
											<div class="col-md-6 col-sm-6 col-xs-12">
												<select class="form-control" id="datastatus"
													name="datastatus">
													<option value="1" selected>开启</option>
													<option value="0">关闭</option>
												</select>
											</div>
										</div>
										<div class="ln_solid"></div>
										<div class="form-group">
											<div class="col-md-6 col-md-offset-3">
												<a type="submit" class="btn btn-primary"
													href="javascript:void(0)"
													onclick="history.back(-1);">取消</a> <input
													id="add" type="button" class="btn btn-success" value="添加"
													onclick="ajaxPost()">
											</div>
										</div>
									</form>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- /page content -->
	<script src="<%=basePath%>vendors/jquery/dist/jquery.min.js"></script>
	<script type="text/javascript">
		function show(obj){
			document.getElementById("shopmoney_box").style.display=(obj.value==4 || obj.value==5)?"":"none";
		}
	</script>
	<script type="text/javascript">
		// ajax post请求：
		function ajaxPost() {
			var partten1 = /^[0-9]{1,10}$/;
	        var partten2 = /^[0-9]{1,18}\.[0-9]{1,2}$/;
	        var partten3 = /^[0-9]{1,10}.0{1,2}$/;
			if ((!partten1.test($("#presenttf").val()) && !partten2.test($("#presenttf").val()))
					|| (!partten1.test($("#presentsg").val()) && !partten3.test($("#presentsg").val()))) {
				alert('请输入正确的数字，任务赠送购物金额只可填写整数，其他例如：10.00（整数最长为18位，小数最长为2位）');
	         	return false;
			}
			var partten4 = /^[0-9]{1,2}$/;
			if (!partten4.test($("#target").val()) || !partten4.test($("#priority").val())) {
				alert('请输入正确的目标值或优先级，最大为99');
				return false;
			}
			$.ajax({
				type : 'POST',
				url : 'toAddTaskList',
				data : $('#myForm').serialize(),
				dataType : 'json',
				success : function(date) {
					switch (date) {
					case -1:
						alert("登录超时，请重新登录");
						top.location.href = "login/${titleId}";
						break;
					case -2:
						alert("已经存在此任务类型，请勿重复添加");
						break;
					case 1:
						alert("添加成功");
						location.href = "taskListIndex";
						break;
					default:
						alert("添加失败，请重新操作");
						break;
					}
				}
			});
		}
	</script>

	<!-- Bootstrap -->
	<script src="<%=basePath%>vendors/bootstrap/dist/js/bootstrap.min.js"></script>
	<!-- FastClick -->
	<script src="<%=basePath%>vendors/fastclick/lib/fastclick.js"></script>
	<!-- NProgress -->
	<script src="<%=basePath%>vendors/nprogress/nprogress.js"></script>
	<!-- bootstrap-daterangepicker -->
	<script src="<%=basePath%>vendors/moment/min/moment.min.js"></script>
	<script
		src="<%=basePath%>vendors/bootstrap-daterangepicker/daterangepicker.js"></script>
	<!-- Chart.js -->
	<script src="<%=basePath%>vendors/Chart.js/dist/Chart.min.js"></script>
	<!-- validator -->
	<script src="<%=basePath%>vendors/validator/validator.js"></script>
	<!-- Custom Theme Scripts -->
	<script src="<%=basePath%>build/js/custom.min.js"></script>
	<!-- Select2 -->
	<script src="<%=basePath%>vendors/select2/dist/js/select2.full.min.js"></script>
</body>
</html>